﻿using System;
using System.Collections.Generic;
using System.Text;
using Lon.Util;

//[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
namespace LonLog
{



    public class LogHelper
    {
        //static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo");
        //static readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror");

        public static event EventHandler<LogMessageArgs> LogEventHandler;

     

        public static void WriteLog(String src,LogType logType, String message)
        {
            EventHandler<LogMessageArgs> tempHandler = LogEventHandler;
            if (tempHandler == null)
            {
                return;
            }

            var args=new LogMessageArgs(logType, message);
            try
            {
                tempHandler(src, args);
            }
            catch (Exception ex)
            {
                NetDebugConsole.WriteLine(ex.Message + ex.StackTrace);
            }
        }
    }

    public class LogMessageArgs : EventArgs
    {
        /// <summary>
        /// 日志类型
        /// </summary>
        private LogType logType;

        public LogType LogType
        {
            get { return logType; }
        }



        /// <summary>
        /// 日志内容
        /// </summary>
        private String message;

        public String Message
        {
            get { return message; }
            set { message = value; }
        }


        private DateTime time;

        public DateTime Time
        {
            get { return time; }
         
        }

        public LogMessageArgs(LogType logType, String message)
        {
            this.time = DateTime.Now;
            this.logType = logType;
            this.message = message;

        }
    }

    public enum LogType
    {
        [EnumString("Info")]
        Info,
        [EnumString("Warnning")]
        Warnning,
        [EnumString("Error")]
        Error,
    }

 
}